package com.expressage.controller;

import com.expressage.po.Complete;
import com.expressage.service.CompleteService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author Gt
 */
@Controller
public class CompleteController {

    Logger logger = Logger.getLogger(CompleteController.class);


    @Autowired
    CompleteService completeService;

    @RequestMapping("/toaddcomplete")
    public String toAdd(){
        return "jspbefore/complete";
    }

    @RequestMapping("/addcomplete")
    public String addcomplete(Complete complete) {
        boolean flag = completeService.insert(complete);
        logger.info(flag ? "添加评价成功" : "添加失败");
        //重定向到帖子列表控制器
        return "redirect:index.action";
    }

    @RequestMapping("jspafter/completelist")
    public String Completelist(Model model){
        logger.info("进入评价列表控制器");
        List<Complete> list = completeService.findAll();
        model.addAttribute("completelist",list);
        return "jspafter/completelist";
    }

    @RequestMapping("/deletecomplete")
    public String deleteComplete(int[] completeid){
        if(completeid.length>0){
            boolean falg = completeService.delete(completeid);
            logger.info(falg?true:false);
        }
        return "redirect:jspafter/completelist.action";
    }

}
